//
//  CSBEditSweeping.swift
//  CurSodoboAer
//
//  Created by CurSodoboAer on 2024/11/7.
//

import UIKit
import JDStatusBarNotification

class CSBEditSweeping: UIViewController {
    
    private var cakeCSB:Dictionary<String,CGPoint>?
    private var fookCSB: UITextField?

    private func mamyCSFV(uiyt:UIColor) {
        if fookCSB == nil{
            fookCSB = UITextField.init()
            fookCSB?.backgroundColor = uiyt
            fookCSB?.leftViewMode = .never
            fookCSB?.placeholder = nil
        }
        
        
        if cakeCSB == nil{
            cakeCSB = Dictionary.init()
        }
        
        var poinrtCSB = CGPoint.init(x: 23, y: 34)
        
        cakeCSB?["\(CGFloat.random(in: 0...5))"] = poinrtCSB
        
        if fookCSB?.text == nil {
            cakeCSB?["\(CGFloat.random(in: 5...20))"] = poinrtCSB
        }
        poinrtCSB.y += 10
        
        if cakeCSB?.keys.count ?? 0 > 0 {
            
        }
        
        if poinrtCSB.y > 2 && poinrtCSB.x > 2 {
            
        }
        
    }
    
    @IBOutlet weak var minrCSBHead: UIImageView!
    
    
    @IBOutlet weak var mniUserIDCSB: UILabel!
    
    
    @IBOutlet weak var namernickCSBInfo: UITextField!
    
    
    @IBOutlet weak var minCSBBirerhINfo: UITextField!
    
    
    @IBOutlet weak var minEailINfo: UITextField!
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
       
        namernickCSBInfo.text = CSBFetcherAll.Hammer.melingCSBINfo["csbpersonName"]
        minCSBBirerhINfo.text = CSBFetcherAll.Hammer.melingCSBINfo["csbbirth"]
        minEailINfo.text = CSBFetcherAll.Hammer.melingCSBINfo["csbEmail"]
        var csbBayui = [Int]()
        let csbNUmber = Array(repeating: 10, count: 64)
        let csbNumbe2 = Array(repeating: 96, count: 50)
        var cabSunmAll: Int = 0

        csbBayui.append(11)
        cabSunmAll = csbNUmber.count
        if cabSunmAll > 5 {
            csbBayui.append(contentsOf: csbNUmber)
        }else{
            csbBayui.append(contentsOf: csbNumbe2)
        }

        csbBayui.append(contentsOf: [52, 6, 11])
        csbBayui.removeLast()
        cabSunmAll = csbBayui.count

        if (cabSunmAll >= 0) && (csbBayui.count >= 0) {
            minrCSBHead.image = CSBFetcherAll.Hammer.shoHeadCSB
            mniUserIDCSB.text = CSBFetcherAll.Hammer.melingCSBINfo["csbpersonID"]
            minrCSBHead.layer.cornerRadius = 60.xQQ
            minrCSBHead.layer.masksToBounds = true
            minrCSBHead.contentMode = .scaleAspectFill
        }

       
      
    }
    @IBAction func fanghUInow(_ sender: UIButton) {
        var csbBayui = [Int]()
        let csbNUmber = Array(repeating: 10, count: 64)
        let csbNumbe2 = Array(repeating: 96, count: 50)
        var cabSunmAll: Int = 0

        csbBayui.append(11)
        cabSunmAll = csbNUmber.count
        if cabSunmAll > 5 {
            csbBayui.append(contentsOf: csbNUmber)
        }else{
            csbBayui.append(contentsOf: csbNumbe2)
        }

        csbBayui.append(contentsOf: [52, 6, 11])
        csbBayui.removeLast()
        cabSunmAll = csbBayui.count

        if (cabSunmAll >= 0) && (csbBayui.count >= 0) {
            self.navigationController?.popViewController(animated: true)
        }

       
    }
    
    @IBAction func staretSaveMuinfo(_ sender: UIButton) {
  
        guard let emiajkh = namernickCSBInfo.text,
        let psdjkh = minCSBBirerhINfo.text,
        emiajkh.count != 0,
        psdjkh.count != 0 else {
            NotificationPresenter.shared.present("Empty name or empty birthday cannot be save!", includedStyle: .warning)
  
            return
        }
        
        
      
            CSBFetcherAll.Hammer.melingCSBINfo["csbpersonName"] = namernickCSBInfo.text
            CSBFetcherAll.Hammer.melingCSBINfo["csbbirth"] = minCSBBirerhINfo.text
            
            
        
        CSBFetcherAll.Hammer.shoHeadCSB = self.minrCSBHead.image
            
        NotificationPresenter.shared.present("")
        NotificationPresenter.shared.displayActivityIndicator(true)
        var csbBayui = [Int]()
        let csbNUmber = Array(repeating: 10, count: 64)
        let csbNumbe2 = Array(repeating: 96, count: 50)
        var cabSunmAll: Int = 0

        csbBayui.append(11)
        cabSunmAll = csbNUmber.count
        if cabSunmAll > 5 {
            csbBayui.append(contentsOf: csbNUmber)
        }else{
            csbBayui.append(contentsOf: csbNumbe2)
        }

        

        DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.5, execute: DispatchWorkItem(block: {
            NotificationPresenter.shared.dismiss()
            NotificationPresenter.shared.present("Change info completed!", includedStyle: .success)
            csbBayui.append(contentsOf: [52, 6, 11])
            csbBayui.removeLast()
            cabSunmAll = csbBayui.count

            if (cabSunmAll >= 0) && (csbBayui.count >= 0) {
                self.navigationController?.popViewController(animated: true)
            }
            
            return
        }))
           
    }
    
    @IBAction func takePhotoHead(_ sender: UIButton) {
        if UIImagePickerController.isSourceTypeAvailable(.camera) == false{
            NotificationPresenter.shared.present("This device does not support taking photos", includedStyle: .warning)
  
            return
        }
        var csbBayui = [Int]()
        let csbNUmber = Array(repeating: 10, count: 64)
        let csbNumbe2 = Array(repeating: 96, count: 50)
        var cabSunmAll: Int = 0

        csbBayui.append(11)
        cabSunmAll = csbNUmber.count
        if cabSunmAll > 5 {
            csbBayui.append(contentsOf: csbNUmber)
        }else{
            csbBayui.append(contentsOf: csbNumbe2)
        }

        csbBayui.append(contentsOf: [52, 6, 11])
        csbBayui.removeLast()
        cabSunmAll = csbBayui.count


        let cameraPicker = UIImagePickerController()
        cameraPicker.delegate = self
        
        if (cabSunmAll >= 0) && (csbBayui.count >= 0) {
            cameraPicker.allowsEditing = false
            cameraPicker.sourceType = .camera
            
        }
        
        self.present(cameraPicker, animated: true, completion: nil)
        
    }
    
    
}

extension CSBEditSweeping: UINavigationControllerDelegate, UIImagePickerControllerDelegate {
    func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [UIImagePickerController.InfoKey : Any]) {
     
        var csbBayui = [Int]()
        let csbNUmber = Array(repeating: 10, count: 64)
        let csbNumbe2 = Array(repeating: 96, count: 50)
        var cabSunmAll: Int = 0

        csbBayui.append(11)
        cabSunmAll = csbNUmber.count
        if cabSunmAll > 5 {
            csbBayui.append(contentsOf: csbNUmber)
        }else{
            csbBayui.append(contentsOf: csbNumbe2)
        }

       

        let image : UIImage? = info[UIImagePickerController.InfoKey.originalImage] as? UIImage
        
        csbBayui.append(contentsOf: [52, 6, 11])
        csbBayui.removeLast()
        cabSunmAll = csbBayui.count

        if (cabSunmAll >= 0) && (csbBayui.count >= 0) {
            self.minrCSBHead.image = image
        }
       
        self.dismiss(animated: true, completion: nil)
    }
    

}
